// Coding by MRX on 2020/8/28 17:35

package main

import (
	"fmt"
	"log"
	"sport_booking/config"
	"sport_booking/dao"
	"sport_booking/routers"
)

func main() {
	// 初始化viper配置
	config.InitViperConfig()
	// 连接数据库
	dao.InitMySQL()
	dao.InitRedis()
	// 程序退出前关闭数据库连接
	defer dao.CloseMySQL()
	defer dao.CloseRedis()
	// 注册路由
	r := routers.SetupRouter()
	// 启动服务
	err := r.Run(fmt.Sprintf("%s:%d", config.ServerHost, config.ServerPort))
	if err != nil {
		log.Println("启动服务失败,ERROR:", err)
	}
}
